<h1>Sản phẩm bán chạy nhất</h1>
<div class="best-selling">

    <?php
    $q = "select b.*, c.ManuName, d.OriginName from ((product b inner join origin d on d.OriginID = b.ProductOriID) 
inner join manufacturer c on c.ManuID = b.ProductManuID) order by b.ProductSell desc";
    $r = mysqli_query($dbc,$q) or die("Query ($q) \n<br/> MySQL Error: " .mysqli_error($dbc));
    if ($r != false) {
        ?>
        <div id="gallery">
            <ul>
                <?php
                while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
                    ?>
                    <li>
                        <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post"
                              name="form<?php echo $row['ProductID']; ?>" width="440px">
                                  <?php
                                  if (isset($_REQUEST["ProductID" . $row['ProductID']]) &&
                                          isset($_SESSION["cartname"]) == true) {
                                      $_SESSION["cartname"]->InsertProduct($_REQUEST["productid" . $row['ProductID']], $_REQUEST["ProductName" . $row['ProductID']], $_REQUEST["quantity" . $row['ProductID']], $_REQUEST["ProductPrice" . $row['ProductID']]);
                                      echo "alert('Tổng số sản phâm đã mua là: " . $_SESSION['cartname']->SumProduct() . "')";
                                  }
                                  ?>

                            <a href="<?php echo $row["ProductImg"]; ?>" title='<underline>Tên:</underline> <?php echo $row["ProductName"]; ?>
                               </br> <underline>Giá:</underline> <?php echo number_format($row["ProductPrice"]) ?> VNĐ
                               </br><underline>Mô tả:</underline> <?php echo $row["ProductDesc"]; ?>
                               </br><underline>Số lượng xem:</underline> <?php echo $row["ProductView"]; ?>
                               </br><underline>Số lượng bán:</underline> <?php echo $row["ProductSell"]; ?>
                               </br><underline>Xuất xứ:</underline> <?php echo $row["OriginName"]; ?>
                               </br><underline>Nhà sản xuất:</underline> <?php echo $row["ManuName"]; ?></a>'>
                                <img src="<?php echo $row["ProductImg"]; ?>" width="150" height="150" alt="" />
                                <p><?php echo $row["ProductName"]; ?></br>Giá: <red><?php echo number_format($row["ProductPrice"]) ?> VNĐ</red> </p></a>
                            <span>
                                <input name="productid<?php echo $row['ProductID']; ?>" type="hidden" 
                                       value="<?php echo $row['ProductID']; ?>" />
                                <input name="productname<?php echo $row['ProductID']; ?>" type="hidden"
                                       value="<?php echo $row['ProductName']; ?>" />
                                <input name="productprice<?php echo $row['ProductID']; ?>" type="hidden"
                                       value="<?php echo $row['ProductPrice']; ?>" />
                                <input name="quantity<?php echo $row['ProductID']; ?>" type="hidden"
                                       value="<?php echo '1'; ?>" />
                                <input name="submit<?php echo $row['ProductID']; ?>" type="submit"  value = 
                                       "Thêm vào giỏ hàng" onclick="<?php
                                       if (isset($_SESSION['cartname']) == false) {
                                           echo "alert('Bạn cần phải đăng nhập để mua hàng');";
                                       }
                                       ?>"/></span>
                        </form>
                    </li>
                <?php }
                ?>
            </ul>
        </div>
        <?php
    } else {
        ?>
        <div id="gallery">
            <p>Không có sản phẩm nào</p>
        </div>
        <?php
    }
    ?>
</div>

